package com.phiture.erp.basic.web.controller.api;

import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import com.phiture.erp.basic.api.pojo.resp.ErpAccountResp;
import com.phiture.erp.basic.api.service.ErpAccountApi;
import com.phiture.erp.basic.core.service.ErpAccountService;
import com.phiture.erp.basic.dal.entity.ErpAccountDO;
import com.phiture.erp.basic.web.convert.ErpAccountConvertMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author YH
 * @date 2025/4/8
 */

@Service
@RequiredArgsConstructor
public class ErpAccountApiServiceImpl implements ErpAccountApi {
    private final ErpAccountService erpAccountService;

    @Override
    public ErpAccountResp validateAccount(Long id) {
        ErpAccountDO erpAccountDO = erpAccountService.validateAccount(id);
        return ErpAccountConvertMapper.INSTANCE.toErpAccountResp(erpAccountDO);
    }

    @Override
    public Map<Long, ErpAccountResp> getAccountMap(Collection<Long> ids) {
        List<ErpAccountDO> accountList = erpAccountService.getAccountList(ids);
        List<ErpAccountResp> erpAccountRespList = ErpAccountConvertMapper.INSTANCE.toErpAccountRespList(accountList);
        return CollectionUtils.convertMap(erpAccountRespList, ErpAccountResp::getId);
    }

    @Override
    public ErpAccountResp getDefaultAccount() {
        ErpAccountDO defaultAccount = erpAccountService.getDefaultAccount();
        return ErpAccountConvertMapper.INSTANCE.toErpAccountResp(defaultAccount);
    }
}
